@echo off
setlocal enabledelayedexpansion

set release=0
set nopause=0
set pp=

for %%A in (%*) do (
	if /I "%%A"=="release" SET release=1
	if /I "%%A"=="pp" SET pp=pp
	if /I "%%A"=="nopause" SET nopause=1
)

if "%release%"=="1" (
	call buildRelease.cmd %pp% nopause
	copy /y Alkaline.js output\* >nul
)
if "%release%"=="0" call buildDebug.cmd nopause

copy /y etc\* output\ >nul

set runJs=cscript //nologo
if exist jsdb set runJs=..\jsdb\jsdb
if exist v8cgi set runJs=..\v8cgi\v8cgi -c ..\v8cgi\v8cgi.conf

echo Running unit tests...
echo.

set tests=
for /R tests %%T in (*.gunit, *.js) do (
	set tests=!tests! "%%T"
)

cd output
%runJs% run_script.js js_test %tests%
cd ..
echo.

if "%nopause%"=="0" pause
